package com.school.campus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.school.campus.domain.vo.ConversationsVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.school.common.annotation.Log;
import com.school.common.core.controller.BaseController;
import com.school.common.core.domain.AjaxResult;
import com.school.common.enums.BusinessType;
import com.school.campus.domain.Conversations;
import com.school.campus.service.IConversationsService;
import com.school.common.utils.poi.ExcelUtil;
import com.school.common.core.page.TableDataInfo;

/**
 * 单聊会话（存储一对一聊天关系）Controller
 *
 * @author wwj
 * @date 2025-11-07
 */
@RestController
@RequestMapping("/campus/conversations")
public class ConversationsController extends BaseController {
    @Autowired
    private IConversationsService conversationsService;

    /**
     * 查询单聊会话（存储一对一聊天关系）列表
     */
    @PreAuthorize("@ss.hasPermi('campus:conversations:list')")
    @GetMapping("/list")
    public TableDataInfo list(Conversations conversations) {
//        startPage();
        List<ConversationsVO> list = conversationsService.selectConversationsVOList(conversations);
        return getDataTable(list);
    }

    /**
     * 导出单聊会话（存储一对一聊天关系）列表
     */
    @PreAuthorize("@ss.hasPermi('campus:conversations:export')")
    @Log(title = "单聊会话（存储一对一聊天关系）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Conversations conversations) {
        List<Conversations> list = conversationsService.selectConversationsList(conversations);
        ExcelUtil<Conversations> util = new ExcelUtil<Conversations>(Conversations.class);
        util.exportExcel(response, list, "单聊会话（存储一对一聊天关系）数据");
    }

    /**
     * 获取单聊会话（存储一对一聊天关系）详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:conversations:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(conversationsService.selectConversationsById(id));
    }

    /**
     * 新增单聊会话（存储一对一聊天关系）
     */
    @PreAuthorize("@ss.hasPermi('campus:conversations:add')")
    @Log(title = "单聊会话（存储一对一聊天关系）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Conversations conversations) {
        return toAjax(conversationsService.insertConversations(conversations));
    }

    /**
     * 修改单聊会话（存储一对一聊天关系）
     */
    @PreAuthorize("@ss.hasPermi('campus:conversations:edit')")
    @Log(title = "单聊会话（存储一对一聊天关系）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Conversations conversations) {
        return toAjax(conversationsService.updateConversations(conversations));
    }

    /**
     * 删除单聊会话（存储一对一聊天关系）
     */
    @PreAuthorize("@ss.hasPermi('campus:conversations:remove')")
    @Log(title = "单聊会话（存储一对一聊天关系）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(conversationsService.deleteConversationsByIds(ids));
    }
}
